Create a web farm of web servers with ARR load balancing

1. INTRODUCTION
--------------------------------------------------------------------------
If you have a very popular website and are unhappy with the uptime and/or 
the response time for this website then you might consider to add one or 
more webservers to your web farm and balance the traffic between the
web servers in this web farm. A web farm is two or more web servers that 
act as a common resource to serve one website. A website that is served 
by a web farm can have faster response time and better uptime compared to 
a website that is served by only one web server because every web
server in a web farm have the same application code (replicated from the
primary web server), web servers in a web farm can share the load and act
as backup servers if one web server goes down.

It is not sure that you get faster response time and/or better uptime if
you add more web servers because it might not be the web servers that are 
the weak point in the network architecture. A chain is not stronger than
its weakeast link and you always need to create a even flow in your 
network and make sure that there isnt any bottlenecks in the network. A
slow response time or a low uptime might be caused by the Internet 
connections, the load balancing or heavy load on database servers
--------------------------------------------------------------------------

2. NETWORK ARCHITECTURE
--------------------------------------------------------------------------
There are a lot of different network architectures that can be used to 
create a web farm of web servers. When you are working on a network 
architecture for your website you can draw your network architecture in a
network diagram so that it is easier for you and others to see the network 
architecture. When your are planning your network architecture you have to 
consider redunancy, fail over and load balancing. Redunancy means that you 
have at least two of every network unit, fail over means that there is a 
mechanism to switch from network units that have failed to network units 
that work and load balancing means that you distribute the load (traffic) 
between network units according to some rules to make use of every network 
unit.

We are going to use Microsoft Web Farm Framework and Microsoft Application 
Request Routing (ARR) to load balance between web servers. Microsoft Web Farm 
Framework and Microsoft Application Request Routing (ARR) can be installed on 
Windows computers that have IIS 7 installed, Microsoft ARR requires that 
Microsoft URL Rewrite also is installed because there is a need to create a
global rewrite rule that redirects incoming request on port 80 to the ARR 
server.

A network architecture that incorporates Microsoft Web Farm Framework (WFF) 
and Microsoft Application Request Routing (ARR) needs at least three different
computers. One computer that acts as the ARR server and the controlling unit 
for the web farm, one computer that acts as the primary web server and one
computer that acts as the secondary web server. If you want to control more
than one website on one ARR server then you need to create multiple server
farms and redirect requests to different server farms based on the host 
name (domain name) in the request. This can be done by adding a condition
to each global rewrite rule with "{HTTP_HOST}" and the host name. 

If you want to create a more redundant network architecture compared to 
required architecture then you can have two dedicated ARR servers with
Network Load Balancing installed on each ARR server and two or more
dedicated web servers. The Network Load Balancing software (NLB) can provide 
you with load balancing and fail over for the ARR servers. Microsoft NLB 
works because messages are broadcasted (multicasted) to every NLB computer 
in  the network and this works if computers are connected to a hub or a layer
2 switch. Microsoft NLB can manipulate the MAC address of two computers
with NLB so that it appears that the computers with NLB have the same 
MAC-address, NLB will therfore work with a layer 2 switch. When you have
two or more ARR servers in the network you can set up shared configuration
for the servers so that configuration settings made on one ARR server are
replicated to the other ARR servers in the network.
--------------------------------------------------------------------------

3. SESSIONS AND SESSION-STATE MODES
--------------------------------------------------------------------------
If you are to create a web farm of web servers and are using sessions 
for your website then you need to store session state in a way that make
the storage independent of which web server that are used for a request. A
visitor on a website that is served by a web farm can be served by 
different web servers on each request and it is therefore important to make
sure that the session state for a visitor doesnt get lost between 
request on the website.

The default session-state mode is "InProc" where the session state are 
stored in memory on the web server and this session-state mode can not be
used when you have a web farm of web servers for a website. When you have
a web farm of web servers you can use the "StateServer" mode, the 
"SQLServer" mode or the "Custom" mode for session state. You specify the
setting for session-state mode in the "web.config" file.

StateServer mode stores session state in a ASP.NET state service that runs
on the computer that should be used as the session state server, the 
ASP.NET state service is installed as a service when ASP.NET and the .NET 
Framework are installed. SQLServer mode stores session state in a SQL Server 
database, you can install the ASP.NET session state SQL database using the 
Aspnet_regsql.exe tool. Custom mode stores session state store session 
state according to your own choice, in a MySQL database for example.

You can read more about session-state modes at MSDN, see the link below.
http://msdn.microsoft.com/en-us/library/ms178586.aspx.
--------------------------------------------------------------------------

4. PREPARATION
--------------------------------------------------------------------------
a) You will need to have at least three different computers to be able to 
use Microsoft WFF and ARR for a load balanced web farm as mentioned before. 
If you want to activate "Application Provisioning" and "Platform Provisioning"
then you need to have IIS 7 installed on all three computers in the network.
Application provisioning is a process where applications, configuration and
content (website content) are replicated from the primary server to 
secondary servers. Platform provisioning is a process where web platform 
components and other modules that are installed on the primary server are 
installed on secondary servers. To be able to use application and plattform 
provisioning you also need to add one user account (Administrator) on each
web server with the same user name and password, this user account is added
in addition to the user account that already exists on each computer.

b) You need a public domain name or a public host name that points to the
public IP-address of your network. You can get a public host name for free
at No-ip.com (www.no-ip.com) where you also can download a software that can
handle dynamic IP-addresses. You need to make sure that incoming web requests
are pointing to the ARR server computer, if you have a router then you need
to port forward requests on port 80 to the IP-address of the ARR server.

c) You need to add an exception for port 80 (TCP) in Windows Firewall on each 
computer in the network. You also need to make sure that you have added 
exceptions for "Core Networking" and "Remote Administration" on the 
computers that should act as web servers.
--------------------------------------------------------------------------

5. INSTALLATION
--------------------------------------------------------------------------
Before you install Microsoft ARR and Microsoft WFF on the ARR server 
computer you need to stop the Windows services called WAS and WMSVC, you 
can do this by typing: net stop was /y <enter> and net stop wmsvc /y <enter>
in the command prompt (dos prompt) or stop these services by browsing to
"Control Panel>Administrative Tools>Services" and stop them.

Download and install Microsoft Application Request Routing (ARR) and
Microsoft Web Farm Framework (WFF) on the computer that should act as the 
ARR server.
--------------------------------------------------------------------------

6. CONFIGURE THE ARR SERVER AND THE WEB FARM
--------------------------------------------------------------------------
Make sure that you have a working website on your primary web server (IIS 7) 
that responds to requests on port 80 (Normally the Default Web Site), the 
content for the website are normally placed in "C:\inetpub\wwwroot".

Open IIS Manager on the ARR server computer, Control Panel>Administrative 
Tools>Internet Information Services (IIS)". Expand the root representing 
the ARR computer under "Connections" on the left side in IIS Manager. 
Expand "Websites" and click on the "Default Web Site", make sure that the
"Default Web site" is running and that it has bindings to port 80. The 
request to the ARR Server Farm are made through the "Default Web Site" and
thats the reason why the "Default Web Site" must be started.

Click on "Server Farms" and then on "Create Server Farm". Give the server 
farm a name (can be anything) and check the checkbox before "Server farm is
available for load balancing". If you want to activate Application provisioning
and Platform provisioning then you should check the checkbox before "Provision
server farm" and enter the user name and password for the common administrator
account that exists on every web server in the web farm. Click the "Next"
button enter the computer name for the primary server (assuming computers are
on the same network), check the checkbox before "Primary server" and click the
"Add" button, enter the computer name for the secondary server and click the 
"Add" button. There are also "advanced settings" when you are adding servers
that can be used to change the port number. You can add an external computer
outside of your internal network by typing the public host name or the public
IP-address (www.microsoft.com for example). Click on the "Finish" button and
answer "Yes" on the question to add a URL rewrite rule for the server farm.

Click on your server farm under "Server Farms" in the left side on the IIS
Manager. Double-click on "Routing Rules", click on "URL Rewrite" under 
"Advanced Routing" on the right side of IIS Manager. Select the URL Rewrite
rule and click on "Edit...", you may note that incoming request to the computer
are redirected to the server farm. Under "Conditions" you can add a condition
that only redirects request made to a specific host to the server farm if
you have more than one server farm on the ARR server. If you want to do this 
then you click on the "Add..." button, add {HTTP_HOST} under "Condition 
input:" and enter the host name under "Pattern", click on "OK" when you are
finished and dont forget to click on "Apply" if you have made any changes.

Click on your server farm under "Server Farms" in the left side on the IIS
Manager. Double-click on "Load Balance", select a load balance algorithm
and click on "Apply" when you are done.

You are now finished with the configuration of a web farm with load balancing
and can test how it works. You can do a "Health Test" for your server farm 
and monitor your server farm from IIS Manager. If you want to check, add
or remove servers from your web farm then you can expand your server farm
under "Server Farms" on the left side of IIS Manager.
--------------------------------------------------------------------------









